package studykana.activity;

import studykana.database.AppData;
import studykana.database.Common;
import toan.da.com.vn.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

	private Button btnHocChuCai;
	private Button btnTracNghiem;
	private Button btnTimHinh;
	// private Databasehandler db;
	private Common common;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_activity);

		btnHocChuCai = (Button) findViewById(R.id.btnTuVung);
		btnTracNghiem = (Button) findViewById(R.id.btnTracNghiem);
		btnTimHinh = (Button) findViewById(R.id.btnTimHinh);

		// copy data from assets
		common = new Common();
		common.copyDBFromAssets("HocTiengNhat", this);
		// load main data and set static.
		try {
			if (AppData.listAllAlphabet == null) {
				common.initDatabase("HocTiengNhat", this);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		btnHocChuCai.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View view) {
				Intent newActivity = new Intent(getApplicationContext(),
						HocChuCaiActivity.class);
				startActivity(newActivity);
			}
		});
		btnTracNghiem.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				goToActivity(TracNghiemActivity.class);
			}
		});

		btnTimHinh.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				goToActivity(TimHinhActivity.class);
			}
		});
	}

	public void goToActivity(Class<? extends Activity> newClass) {
		Intent newActivity = new Intent(getApplicationContext(), newClass);
		startActivity(newActivity);
	}

}
